/*  704. 二分查找 */
/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function (nums, target) {
	let left = 0,
		right = nums.length - 1
	while (left <= right) {
		const median = left + ((right - left) >> 1)
		if (target === nums[median]) {
			return median
		} else if (target > nums[median]) {
			left = median + 1
		} else {
			right = median - 1
		}
	}
	return -1
}
const index = search([-1, 0, 3, 5, 9, 12], 2)
console.log('index :>>', index)
